#!/bin/bash
source /etc/profile

dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"
mysql -uroot -proot -hhadoop2<<EOF
use sqlserver;
select substr(SENDTIME,1,14),STATIONCODE,OILCODE,COUNT(*),SUM(LITRE)/1000,SUM(REALAMOUNT)/100
FROM (
select 
SENDTIME,OILCODE,LITRE,REALAMOUNT,ORDER_DEAL,
if(STATIONCODE = '58008','58010',STATIONCODE)  STATIONCODE
from oracleanditem.TBL_ORDERDETAILS WHERE LITRE != 0 and ORDER_DEAL = 4 and  substr(SENDTIME,1,10)='$dt'
union all
select  
SENDTIME,OILCODE,LITRE,REALAMOUNT,ORDER_DEAL,
if(STATIONCODE = '58008','58010',STATIONCODE)  STATIONCODE
from oraclecd.TBL_ORDERDETAILS WHERE LITRE != 0 and ORDER_DEAL = 4 and  substr(SENDTIME,1,10)='$dt'
) a  GROUP BY substr(SENDTIME,1,14),STATIONCODE,OILCODE;
EOF
